<?
include("dbconn.php");
$lang = $_GET['lang'];
	if(!$conn){
		exit();
	}
	else{
		if(!mysql_select_db("happyweb_db",$conn)){
			exit();
		}
		else{
			$SQL= "SELECT
			refillpromotions.Id,
			refillpromotions.Title,
			refillpromotions.Pic,
			refillpromotions.Detail,
			refillpromotions.Link,
			refillpromotions.ViewType,
			refillpromotions.W,
			refillpromotions.H,
			refillpromotions.Language,
			refillpromotions.Active
			FROM
			refillpromotions ";
			if($lang!=''){
				$SQL .=" Where language='" .$lang."'";
			}	
			$SQL .=" ORDER BY refillpromotions.Id ASC";
			$result = mysql_query($SQL,$conn);
			if(!$result){
				//echo mysql_error();
				exit();
			}
			else{
				if(mysql_num_rows($result)>0){
					$pic='';
					$rnd;
					$rnd = rand(0,mysql_num_rows($result)-1);
					mysql_data_seek($result,$rnd);
					$row = mysql_fetch_assoc($result);
    				$pic =  $row['Pic'];
    				$link = $row['Link'];
  					echo '<a href="'.$link.'"><img src="../picture/banner/'.$pic.'" border="0"></a>';
				}
				else{
					
				}
			}
		}
	}
?>